import { EntitySchema } from 'typeorm'

export default new EntitySchema({
  name: 'Menu',
  comment: '菜单表',
  columns: {
    menuId: {
      type: 'int',
      generated: 'increment',
      primary: true,
      comment: '菜单id'
    },

    menuName: {
      type: 'varchar',
      length: 200,
      comment: '菜单名称'
    },

    menuOrder: {
      type: 'int',
      comment: '菜单排序'
    },

    parentId: {
      type: 'int',
      nullable: true,
      comment: '父菜单Id'
    },

    parentIds: {
      type: 'varchar',
      length: 100,
      nullable: true,
      comment: '当前节点所有父节点id， 格式： [0][1][7][10]'
    },

    menuType: {
      type: 'enum',
      enum: [1, 2, 3, 4],
      // ，5-外链
      comment: '菜单类型 1-目录，2-菜单，3-系统，4-按钮'
    },

    component: {
      type: 'varchar',
      length: 255,
      comment: '前端组件路径',
      nullable: true
    },

    path: {
      type: 'varchar',
      length: 255,
      comment: '前端路由',
      nullable: true
    },

    name: {
      type: 'varchar',
      length: 70,
      nullable: true,
      comment: '前端路由中name， 可通过router.push跳转， 如果是目录，可以为空'
    },

    icon: {
      type: 'text',
      comment: '菜单图标， 可以是element-ui内部提供的字符串，也可以是http://xxx url链接地址',
      nullable: true
    },

    buttonName: {
      type: 'varchar',
      length: 20,
      nullable: true,
      comment: '按钮名称'
    },
    buttonCode: {
      type: 'varchar',
      length: 20,
      nullable: true,
      comment: '按钮Code'
    },

    createById: {
      type: 'int',
      nullable: true,
      comment: '创建人id'
    },

    createTime: {
      type: 'datetime',
      nullable: true,
      default: () => 'CURRENT_TIMESTAMP'
    },

    updateTime: {
      type: 'datetime',
      nullable: true,
      default: () => 'CURRENT_TIMESTAMP'
    },
    isDelete: {
      type: 'int',
      default: 0,
      comment: '是否被删除; 0-未删除， 1-已删除'
    },
    hidden: {
      type: 'int',
      nullable: true,
      comment: '菜单是否显示 1-显示,0-隐藏'
    },
    updateId: {
      type: 'int',
      comment: '更新人Id',
      nullable: true
    },
    isHref: {
      type: 'int',
      comment: '是否外部链接 1-是，0-否',
      default: 0
    },
    href: {
      type: 'text',
      comment: '外部地址 http或者https',
      nullable: true
    },
    isCache: {
      type: 'int',
      comment: '是否缓存路由, 1-缓存, 0-不缓存',
      default: 0,
      nullable: true
    }
  }
})
